package com.sx.art2.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.sx.art2.beans.Category;
import com.sx.art2.service.CategoryService;
@Controller
@RequestMapping("/Category")
public class CategoryController {
	
	@Autowired
	CategoryService categoryService;
	
	@RequestMapping("/insert")
	public ModelAndView insert(Category category) {
		System.out.println("category");
		ModelAndView mv=new ModelAndView();
		categoryService.insert(category);
		mv.setViewName("success");
		return mv;
	}
	@RequestMapping("/selectById")
	public ModelAndView selectById(int categoryId) {
		ModelAndView mv=new ModelAndView();
		Category category=categoryService.selectById(1);
		System.out.println(category.getCategoryId());
		mv.addObject(category);
		mv.setViewName("categoryUpdate");
		return mv;
	}
	@RequestMapping("/delete")
	public ModelAndView delete(int categoryId) {
		ModelAndView mv=new ModelAndView();
		categoryService.delete(categoryId);
		mv.setViewName("redirect:/Category/list");
		return mv;
	}
	@RequestMapping("/update")
	public ModelAndView update(Category category) {
		ModelAndView mv=new ModelAndView();
		categoryService.update(category);
		mv.setViewName("redirect:/Category/list");
		return mv;
	}
	
	@RequestMapping("/list")
	public ModelAndView list() {		
		ModelAndView mv=new ModelAndView();
		List<Category> categoryList=categoryService.list();
		mv.addObject("categoryList", categoryList);
		mv.setViewName("admin/Category_Manage");
		return mv;
	}
	@RequestMapping("/allCategory")
	public ModelAndView allCategory() {		
		ModelAndView mv=new ModelAndView();
		List<Category> categoryList=categoryService.list();
		mv.addObject("categoryList", categoryList);
		mv.setViewName("addArt");
		return mv;
	}

}
